<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域 -->
    <el-card>
      <el-row :gutter="20">
        <el-col :span="7">
          <!-- 商品搜索框 -->
          <div class="grid-content bg-purple">
            <el-input
              placeholder="请输入内容"
              v-model="queryInfo.query"
              clearable
            >
              <el-button
                slot="append"
                icon="el-icon-search"
              >
              </el-button>
            </el-input>
          </div>
        </el-col>
      </el-row>
      <!-- 表格区域 -->
      <el-table
        :data="orderList"
        border
        stripe
      >
        <el-table-column
          type="index"
          label="编号"
          width="80px"
        >
        </el-table-column>
        <el-table-column
          prop="order_number"
          label="订单编号"
          width="220px"
        >
        </el-table-column>
        <el-table-column
          label="订单价格"
          prop="order_price"
        >
        </el-table-column>
        <el-table-column label="是否付款">
          <el-tag :type="isPayed">{{ payOrNot }}</el-tag>
        </el-table-column>
        <el-table-column
          label="下单时间"
          prop="create_time"
        >
        </el-table-column>
        <el-table-column label="操作">
          <el-button
            type="primary"
            icon="el-icon-edit"
            size="mini"
          ></el-button>
          <el-button
            type="success"
            icon="el-icon-setting"
            size="mini"
          ></el-button>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[1, 3, 5, 7, 9, 13]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  data () {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 5
      },
      orderList: [],
      total: 0
    }
  },
  created () {
    this.getOrderList()
  },
  methods: {
    async getOrderList () {
      const { data: res } = await this.$http.get('orders', { params: this.queryInfo })
      if (res.meta.status !== 200) {
        this.$message.error('获取订单列表失败!')
      }
      this.orderList = res.data.goods
      this.total = res.data.total
      console.log(res)
    },

    handleSizeChange (newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrderList()
    },
    handleCurrentChange (newPage) {
      this.queryInfo.pagenum = newPage
      this.getOrderList()
    }
  },
  computed: {
    isPayed () {
      if (this.orderList.pay_status === '1') {
        return 'success'
      } else {
        return 'danger'
      }
    },
    payOrNot () {
      if (this.orderList.pay_status === '1') {
        return '已付款'
      } else {
        return '未付款'
      }
    }
  }
}
</script>

<style lang="less" scoped>
.el-table {
  margin-top: 15px;
}
.el-pagination {
  margin-top: 15px;
  text-align: center;
}
</style>
